﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using WindowsPhonePostClient;

namespace MeetingFinder
{
    public partial class CreateMeetingForm : PhoneApplicationPage
    {
        public CreateMeetingForm()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            string projectGroupSelected = NavigationContext.QueryString["groupSelected"];
            groupSelected.Text = projectGroupSelected;
            base.OnNavigatedTo(e);
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void submitButton_Click(object sender, RoutedEventArgs e)
        {
            var currentApp = App.Current as App;

            string meetingDateTime = dateInput.ValueString + " " + timeInput.ValueString;
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("title", meetingTitleInput.Text);
            parameters.Add("content", meetingDescriptionInput.Text);
            parameters.Add("creator_id", currentApp._userID);
            parameters.Add("group_id", "TEMP");//need to set group ID
            parameters.Add("is_confirmed", "false");
            parameters.Add("is_completed", "false");
            parameters.Add("f_location", meetingLocationInput.Text);
            parameters.Add("f_time", Convert.ToDateTime(meetingDateTime));

            PostClient proxy = new PostClient(parameters);
            proxy.DownloadStringCompleted += (senderM, eM) =>
            {
                if (eM.Error == null)
                {
                    //Process the result... 
                    string data = eM.Result;
                }
            };
            proxy.DownloadStringAsync(new Uri(StringConstants._serverAddress + StringConstants._postNewMeetingAPI, UriKind.Absolute));
        }


    }
}